/*
 * Copyright (C) 2000-2007 Wang Pengcheng <wpc0000@163.com>
 * Licensed to the Wang Pengcheng under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The LGPL licenses this file to You under the GNU Lesser General Public
 * Licence, Version 2.0  (the "License"); you may not use this file except in
 * compliance with the License.  You may obtain a copy of the License at
 *
 *     http://www.gnu.org/licenses/lgpl.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//28 Aug 2007
package cn.edu.whu.data;

import java.util.*;

public class VarList{

	/**
	 * Because of many things ,I make them in the class.
	 * And you should get this by the index.
	 * Each varchar is in the template.
	 * 
	 */
	//$PACKAGE is the package in the class, the class package is the "$PACKAGE"+".database"
	//$DATA is the basic name in the class, It will Create the class by name of "$DATA"+"Bean"
	String[] var = { "$PACKAGE", "$DATA", "$TYPE", "$NAME", "$PKGURL","$METHODNAME",
			"$RESULTMAP", "$SELECTONE", "$KEY", "$INSERT", "$UPDATE","$DBCREATEINFOR","$DBTABLENAME" };
	String[] value=new String[var.length];
	
	public VarList(){
		for(int i=0;i<value.length;i++){
			value[i]="";
		}
	}
	public String getValue(String var){
		int i=0;
		while(i<this.var.length){
			if(var.equals(this.var[i])){
				break;
			}
			i++;
		}
		if(i>=this.var.length){
			return null;
		}
		return value[i];
	}
	
	public String getValue(int index){
		if(index<var.length){
			return value[index];
		}else{
			return null;
		}
	}
	
	public void setValue(String var,String value){
		int i=0;
		while(i<this.var.length){
			if(var.equals(this.var[i])){
				break;
			}
			i++;
		}
		if(i<this.var.length){
			this.value[i]=value;
		}
	}
	/**
	 * Set the value in the var list and value list
	 * @param index the index in the var list
	 * @param value the value
	 */
	public void setValue(int index,String value){
		if(index<var.length){
			this.value[index]=value;
		}
	}
	
	public int length(){
		return var.length;
	}
	
	public String getVar(int index){
		if(index<var.length){
			return var[index];
		}else{
			return null;
		}
	}
	
	public String toString(){
		String s="";
		for(int i=0;i<var.length;i++){
			s+=var[i]+"="+value[i]+"\n";
		}
		return s;
	}
}
